Tool Execution
BindAI tools are Python functions wrapped by the@tool decorator.
When an agent decides to use a tool, BindAI looks up the registered tool and executes the underlying Python function with the arguments supplied to it.
The current tool execution model is intentionally simple and predictable.
How Tool Execution Works
The basic execution flow is:Creating a Tool
Create a tool by decorating a Python function with@tool.
Tool.
The resulting tool contains the information BindAI needs to expose and execute the function.
Tool Objects
ATool represents a callable capability.
Conceptually, a tool contains:
@tool decorator rather than constructing Tool objects manually.
Tool Names
By default, the tool name comes from the Python function name.Tool Descriptions
A tool description communicates what the operation does. For example:Registering a Tool
Tools can be registered directly on an agent.The Tool Registry
Registered tools are stored in aToolRegistry.
The registry is responsible for finding a tool by name.
Conceptually:
Tool.
This allows the execution layer to work with tools by their registered names rather than depending directly on a particular Python function.
Tool Executor
BindAI uses aToolExecutor to execute registered tools.
The executor works with a ToolRegistry and resolves the requested tool before invoking it.
Conceptually:
What Happens During Execution?
The execution process can be represented as:Tool Arguments
Arguments are passed to the underlying Python function according to its signature. For example:Tool Results
Tool execution produces aToolResult.
A successful result conceptually contains:
Unknown Tools
If execution receives a tool name that is not registered, the execution layer should not attempt to call an unrelated function. The result represents the failed tool lookup. Conceptually:Tool Errors
The executor ultimately delegates the operation to the registered tool. Tools can handle expected application-level failures themselves. For example:Exceptions
Not every exception should be converted into a normal tool result. Unexpected programming errors should generally remain visible during development so they can be diagnosed and fixed. Expected operational failures may be handled explicitly. For example:Tool Context
The current BindAI tool API does not require an implicitExecutionContext or context.variables object for standard tool execution.
Instead, tools should receive the information they need through explicit function parameters.
For example:
Passing Application State
If a tool needs application-specific state, pass the required information explicitly when that state is part of the tool’s public input. For example:Avoid Global State
Avoid storing request-specific information in global variables. Avoid:- Test
- Reuse
- Debug
- Reason about
- Execute safely
Tool Execution and Workflows
Tools can be used as part of larger application workflows. A workflow can provide the values required by a tool and use the resulting tool output in later processing. The important distinction is:- Tool parameters represent inputs required by the function.
- Tool output /
ToolResultrepresents the result of execution. - Workflow state belongs to the workflow implementation.
- Agent execution state should not be assumed to be an implicit tool context.
Tool Lifecycle
A complete tool lifecycle is:Tool Execution and the Agent
The agent coordinates model interaction and tool execution. Conceptually:Tool Execution and Providers
Tool execution is separated from the specific language model provider. Conceptually:Tool Context vs Explicit Inputs
Prefer explicit inputs when the value is genuinely part of the tool’s operation. For example:Tool Context and Security
Explicit inputs do not remove the need for authorization. For example:document_id is supplied explicitly does not mean the requested operation should automatically be allowed.
The application should still verify:
- Authentication
- Authorization
- Resource ownership
- Input validity
- Operation scope
Tool Execution with External Services
When a tool communicates with an external service, keep the external-service logic isolated where practical. For example:Tool Execution with Memory
Tools can operate alongside BindAI memory. For example:Tool Execution with Knowledge
Tools can also operate alongside BindAI knowledge and retrieval. For example:Tool Execution with Multi-Agent Systems
Different agents can have different tool sets. For example:Testing Tool Execution
Tool execution should be tested independently from the language model whenever possible. For example, test the underlying operation directly:- Tool creation
- Tool registration
- Tool lookup
- Positional arguments
- Keyword arguments
- Successful execution
- Unknown tools
- Tool failures
- Multiple registered tools
- Security and authorization boundaries
Complete Example
Best Practices
- Use explicit function parameters for tool inputs.
- Add Python type hints.
- Give tools clear names.
- Write concise descriptions.
- Use docstrings when appropriate.
- Keep tools focused on one responsibility.
- Avoid request-specific global state.
- Handle expected application failures clearly.
- Keep tool outputs predictable.
- Validate inputs before performing external operations.
- Keep authorization in application code.
- Do not expose credentials through tool parameters or results.
- Do not depend on undocumented execution-context APIs.
- Test tool functions independently from language-model execution.
- Use dedicated connections for reusable external integrations.
- Use workflows for complex orchestration.
Summary
BindAI’s current tool execution model is intentionally straightforward. A Python function is converted into aTool using @tool, registered with an agent, resolved through the tool registry, and executed as part of agent execution.
The underlying Python function receives the arguments defined by its signature, and the execution system represents the outcome through tool-result handling.
For standard tools, inputs should be explicit rather than relying on an implicit ExecutionContext or context.variables abstraction.
This design keeps tools:
- Explicit
- Testable
- Reusable
- Provider-independent
- Easier to secure
